import request from '@/utils/request'
// import qs from 'qs'

// 获取ALG信息
export function getAlgInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alg/getAlgInfo',
    method: 'post',
    data
  })
}

// 修改ALG信息
export function setAlgInfo (params) {
  var data = fromData(params)
  return request({
    url: '/alg/setAlgInfo',
    method: 'post',
    data
  })
}

// 获取预期端口超时时间
export function getOpcTimeout (params) {
  var data = fromData(params)
  return request({
    url: '/alg/getOpcTimeout',
    method: 'post',
    data
  })
}

// 设置预期端口超时时间
export function setOpcTimeout (params) {
  var data = fromData(params)
  return request({
    url: '/alg/setOpcTimeout',
    method: 'post',
    data
  })
}

// 获取预期端口阈值
export function getExpectMax (params) {
  var data = fromData(params)
  return request({
    url: '/alg/getExpectMax',
    method: 'post',
    data
  })
}

// 设置预期端口阈值
export function setExpectMax (params) {
  var data = fromData(params)
  return request({
    url: '/alg/setExpectMax',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
